#!/bin/bash
#
# rundeckd    Startup script for the rundeck

# Source function library
. /lib/lsb/init-functions
. /etc/rundeck/profile

prog="rundeckd"
PIDFILE=/var/run/$prog.pid

function shutdown()
{
    echo -n "`date +"%d.%m.%Y %T.%3N"` - Stopping ${prog}"
    killproc -p $PIDFILE "$rundeckd"
}

echo -n "`date +"%d.%m.%Y %T.%3N"` - Starting ${prog}"
cd /var/log/rundeck
nohup su -s /bin/bash rundeck -c "$rundeckd &>>/var/log/rundeck/service.log" &
PID=$!
echo $PID > $PIDFILE

trap shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP

while pgrep -F /var/run/${prog}.pid > /dev/null; do sleep 5; done
